package cn.lili.modules.payment.entity.dto;

import cn.lili.modules.payment.entity.dos.CombinePaymentLog;
import cn.lili.modules.payment.entity.dos.PaymentLog;
import cn.lili.modules.payment.entity.dos.PaymentSubsidies;
import cn.lili.modules.payment.entity.enums.PaymentMethodEnum;
import cn.lili.modules.payment.entity.enums.PaymentSceneEnums;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * 系统内部支付回调模型
 */
@Builder
@Data
public class PaymentCallback implements Serializable {

    private static final long serialVersionUID = -3079537144412530354L;

    @ApiModelProperty(value = "是否合单支付")
    private Boolean isCombine = false;
    //--------------------------------普通支付--------------------------------

    @ApiModelProperty(value = "支付日志")
    private PaymentLog paymentLog;

    //-----------------------------------合单支付-----------------------------------
    @ApiModelProperty(value = "合单支付")
    private CombinePaymentLog combinePaymentLog;

    @ApiModelProperty(value = "支付日志")
    List<PaymentLog> paymentLogs;

    //-----------------------------------补差支付-----------------------------------
    @ApiModelProperty(value = "补差支付")
    private PaymentSubsidies paymentSubsidies;


    /**
     * 获取支付场景
     *
     * @return 支付场景
     */
    public PaymentSceneEnums getScene() {
        if (this.getPaymentLog() != null) {
            return PaymentSceneEnums.valueOf(this.getPaymentLog().getPaymentScene());
        } else {
            return PaymentSceneEnums.valueOf(this.getPaymentLogs().get(0).getPaymentScene());
        }
    }

    /**
     * 是否第三方支付
     *
     * @return 是否第三方支付
     */
    public Boolean isThirdPayment() {
        if (this.getPaymentLog() != null) {
            return PaymentMethodEnum.valueOf(this.getPaymentLog().getPaymentMethod()).getThirdPayment();
        } else {
            return PaymentMethodEnum.valueOf(this.getPaymentLogs().get(0).getPaymentMethod()).getThirdPayment();
        }
    }
}
